package com.model;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

public class Pagenation  implements Serializable {

    private  int pageSize = 10;

    private String pageNumber="1";
    private int startRowNumber;
    private int endRowNumber;
    private int totalNumber=10;
    private String startTime;
    private String endTime;
    private int pageSizeParam;
    private String queryStr;

    public int getPageSizeParam() {
        return pageSizeParam;
    }

    public void setPageSizeParam(int pageSizeParam) {
        this.pageSizeParam = pageSizeParam;
    }

    public String getQueryStr() {
        return queryStr;
    }

    public void setQueryStr(String queryStr) {
        this.queryStr = queryStr;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }


    public int getStartRowNumber() {
        if(StringUtils.isNumeric(this.pageNumber)){
            int pageNumber = Integer.parseInt(this.pageNumber);
            if(pageNumber>=1 ){
                int tempNumber = (pageNumber-1)*pageSize;

                if(tempNumber<totalNumber){
                    startRowNumber =(pageNumber-1)*pageSize;
                    return startRowNumber;
                }else{
                    return totalNumber/pageSize*pageSize;
                }
            }
        }

        return 0;
    }

    public void setStartRowNumber(int startRowNumber) {
        this.startRowNumber = startRowNumber;
    }

    public int getEndRowNumber() {
        if(StringUtils.isNumeric(this.pageNumber)) {
            int pageNumber = Integer.parseInt(this.pageNumber);
            if (pageNumber >= 1) {
                this.endRowNumber = (pageNumber) * pageSize <= totalNumber ? pageSize : totalNumber % pageSize;
                return endRowNumber;
            }
        }
        return endRowNumber;

    }

    public void setEndRowNumber(int endRowNumber) {
        this.endRowNumber = endRowNumber;
    }

    public String getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(String pageNumber) {
        if(StringUtils.isNumeric(pageNumber)){
            this.pageNumber =pageNumber;
        }else{
            this.pageNumber ="1";
        }
    }


    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(int totalNumber) {
        this.totalNumber = totalNumber;
    }




}
